#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>

#include "vbus.h"

MODULE_AUTHOR("Arkins");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Virtual Driver");

#define VDRIVER_NAME "vdriver"

static int vdriver_probe(struct device *dev);
static int vdriver_remove(struct device *dev);

static struct module *vbus_mod = NULL;

static struct device_driver vdriver = {
    .name	= VDRIVER_NAME,
    .owner	= THIS_MODULE,
    .probe	= vdriver_probe,
    .remove	= vdriver_remove,
    .probe_type = PROBE_FORCE_SYNCHRONOUS,
};

static int vdriver_probe(struct device *dev)
{
    printk("vdriver_probe init_name=%s\n", dev->init_name);
    return 0;
}

static int vdriver_remove(struct device *dev)
{
    printk("vdriver_remove init_name=%s\n", dev->init_name);
    return 0;
}

static int __init vdriver_init(void)
{
    int ret;
    printk("vdriver init\n");
    vbus_mod = find_module("v_bus");
    if (vbus_mod == NULL) {
        printk("vdriver vbus_mod == NULL\n");
        return 1;
    }
    if (!try_module_get(vbus_mod)) {
        printk("vdriver try_module_get error\n");
        return 1;
    }
    ret = vbus_register_driver(&vdriver);
    if (ret) {
        printk("driver_register ret=%d\n", ret);
        module_put(vbus_mod);
        return 1;
    }
    return 0;
}

static void __exit vdriver_exit(void)
{
    printk("vdriver exit\n");
    vbus_unregister_driver(&vdriver);
    module_put(vbus_mod);
    vbus_mod = NULL;
}

module_init(vdriver_init)
module_exit(vdriver_exit)
